package com.ls.server.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.File;

/**
 * Web MVC配置
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Value("${file.upload.path:./upload}")
    private String uploadPath;

    @Value("${file.access.path:/files}")
    private String accessPath;

    /**
     * 添加静态资源处理器
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 文件上传路径映射
        String uploadResourcePath = "file:" + new File(uploadPath).getAbsolutePath() + File.separator;
        // 配置映射关系
        registry.addResourceHandler(accessPath + "/**").addResourceLocations(uploadResourcePath);
    }
} 